package com.kk.xhr.model.dao;

import static com.kk.xhr.model.dao.WorkTimeDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.kk.xhr.model.entity.WorkTime;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface WorkTimeMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    BasicColumn[] selectList = BasicColumn.columnList(id, earlyBegin, earlyEnd, lateBegin, lateEnd, flexDuration, duration, status);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Integer.class)
    int insert(InsertStatementProvider<WorkTime> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("WorkTimeResult")
    Optional<WorkTime> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="WorkTimeResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="early_begin", property="earlyBegin", jdbcType=JdbcType.TIME),
        @Result(column="early_end", property="earlyEnd", jdbcType=JdbcType.TIME),
        @Result(column="late_begin", property="lateBegin", jdbcType=JdbcType.TIME),
        @Result(column="late_end", property="lateEnd", jdbcType=JdbcType.TIME),
        @Result(column="flex_duration", property="flexDuration", jdbcType=JdbcType.INTEGER),
        @Result(column="duration", property="duration", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT)
    })
    List<WorkTime> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, workTime, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, workTime, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default int deleteByPrimaryKey(Integer id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default int insert(WorkTime record) {
        return MyBatis3Utils.insert(this::insert, record, workTime, c ->
            c.map(earlyBegin).toProperty("earlyBegin")
            .map(earlyEnd).toProperty("earlyEnd")
            .map(lateBegin).toProperty("lateBegin")
            .map(lateEnd).toProperty("lateEnd")
            .map(flexDuration).toProperty("flexDuration")
            .map(duration).toProperty("duration")
            .map(status).toProperty("status")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default int insertSelective(WorkTime record) {
        return MyBatis3Utils.insert(this::insert, record, workTime, c ->
            c.map(earlyBegin).toPropertyWhenPresent("earlyBegin", record::getEarlyBegin)
            .map(earlyEnd).toPropertyWhenPresent("earlyEnd", record::getEarlyEnd)
            .map(lateBegin).toPropertyWhenPresent("lateBegin", record::getLateBegin)
            .map(lateEnd).toPropertyWhenPresent("lateEnd", record::getLateEnd)
            .map(flexDuration).toPropertyWhenPresent("flexDuration", record::getFlexDuration)
            .map(duration).toPropertyWhenPresent("duration", record::getDuration)
            .map(status).toPropertyWhenPresent("status", record::getStatus)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default Optional<WorkTime> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, workTime, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default List<WorkTime> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, workTime, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default List<WorkTime> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, workTime, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default Optional<WorkTime> selectByPrimaryKey(Integer id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, workTime, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    static UpdateDSL<UpdateModel> updateAllColumns(WorkTime record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(earlyBegin).equalTo(record::getEarlyBegin)
                .set(earlyEnd).equalTo(record::getEarlyEnd)
                .set(lateBegin).equalTo(record::getLateBegin)
                .set(lateEnd).equalTo(record::getLateEnd)
                .set(flexDuration).equalTo(record::getFlexDuration)
                .set(duration).equalTo(record::getDuration)
                .set(status).equalTo(record::getStatus);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(WorkTime record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(earlyBegin).equalToWhenPresent(record::getEarlyBegin)
                .set(earlyEnd).equalToWhenPresent(record::getEarlyEnd)
                .set(lateBegin).equalToWhenPresent(record::getLateBegin)
                .set(lateEnd).equalToWhenPresent(record::getLateEnd)
                .set(flexDuration).equalToWhenPresent(record::getFlexDuration)
                .set(duration).equalToWhenPresent(record::getDuration)
                .set(status).equalToWhenPresent(record::getStatus);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default int updateByPrimaryKey(WorkTime record) {
        return update(c ->
            c.set(earlyBegin).equalTo(record::getEarlyBegin)
            .set(earlyEnd).equalTo(record::getEarlyEnd)
            .set(lateBegin).equalTo(record::getLateBegin)
            .set(lateEnd).equalTo(record::getLateEnd)
            .set(flexDuration).equalTo(record::getFlexDuration)
            .set(duration).equalTo(record::getDuration)
            .set(status).equalTo(record::getStatus)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: work_time")
    default int updateByPrimaryKeySelective(WorkTime record) {
        return update(c ->
            c.set(earlyBegin).equalToWhenPresent(record::getEarlyBegin)
            .set(earlyEnd).equalToWhenPresent(record::getEarlyEnd)
            .set(lateBegin).equalToWhenPresent(record::getLateBegin)
            .set(lateEnd).equalToWhenPresent(record::getLateEnd)
            .set(flexDuration).equalToWhenPresent(record::getFlexDuration)
            .set(duration).equalToWhenPresent(record::getDuration)
            .set(status).equalToWhenPresent(record::getStatus)
            .where(id, isEqualTo(record::getId))
        );
    }
}